<!-- 高频交易 -->
<script lang="ts" setup>
import {
  listHighFreqTradeThreshold,
  getHighFreqTradeThreshold,
  delHighFreqTradeThreshold,
  addHighFreqTradeThreshold,
  updateHighFreqTradeThreshold,
} from "@/api/system/highFreqTradeThreshold";
import { onMounted, getCurrentInstance, ref, reactive, toRefs } from "vue";
const { proxy } = getCurrentInstance();
const loading = ref(true);
const total = ref(0);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    highFreqTradeCount: undefined,
    params: {},
  },
});
let hasRes = ref(false);
const { queryParams } = toRefs(data);
let FormRef = ref({
  highFreqTradeCount: "",
  highFreqTradeAmount: "",
});
/** 查询高频交易列表 */
const getList = async () => {
  loading.value = true;
  const res = await listHighFreqTradeThreshold(queryParams.value);
  if (res.rows.length) {
    FormRef.value = res.rows[0];
    hasRes.value = true;
  }
  total.value = res.total;
  loading.value = false;
};
const Save = async () => {
  if (hasRes) {
    let res = await updateHighFreqTradeThreshold(
      FormRef.value
    );
    if(res.code == 200){
      proxy?.$modal.msgSuccess("操作成功");
    }
  } else {
    let res = await addHighFreqTradeThreshold(
      FormRef.value
    );
    if(res.code == 200){
      proxy?.$modal.msgSuccess("操作成功");
    }
  }
};
onMounted(() => {
  getList();
});
</script>

<template>
  <VCard>
    <VCardText class="py-10">
      <VRow class="match-height">
        <VCol cols="12" md="4">
          <VRow no-gutters>
            <VCol cols="12" md="3" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >交易次数</label
              >
            </VCol>
            <VCol cols="12" md="7">
              <AppTextField
                v-model="FormRef.highFreqTradeCount"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入交易次数"
                density="compact"
              />
            </VCol>
          </VRow>
        </VCol>
        <VCol cols="12" md="3">
          <VRow no-gutters>
            <VCol cols="12" md="5" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >合计金额 &nbsp;&nbsp;&nbsp;&nbsp; 大于</label
              >
            </VCol>
            <VCol cols="12" md="6">
              <AppTextField
                v-model="FormRef.highFreqTradeAmount"
                label=""
                :rules="[requiredValidator]"
                placeholder="请输入"
                density="compact"
              />
            </VCol>
            <VCol cols="12" md="1" class="d-flex align-items-center">
              <label
                class="v-label text-body-2 text-high-emphasis"
                for="firstName"
                >&nbsp;&nbsp; 元</label
              >
            </VCol>
          </VRow>
        </VCol>

        <VCol cols="12" md="4" class="display_flex-end">
          <VBtn color="primary" density="compact" @click="Save()"> 保存 </VBtn>
        </VCol>
      </VRow>
    </VCardText>
  </VCard>
</template>

<style lang="scss">
.display_flex-end {
  display: flex;
  align-items: flex-end;
  gap: 15px;
}

.mb-1 {
  margin-block-end: 0 !important;
}
</style>
